layui.use(['form','jquery','layer'],function () {
    var form = layui.form;
    var $ = layui.$;
    var layer = layui.layer;
    var user = JSON.parse(localStorage.getItem("user"));
    $('#createId').val(user.data.userId);
    $('#close').click(function () {
        var layer = parent.layer;
        layer.close(layer.index);
    });
    $(document).click(function () {
        parent.$('.tab').hide();
    });
    $('#addDept').click(function () {
        $.ajax({
            url: '/SyDept/addDept',
            data: form.val('deptForm'),
            type: 'post',
            dataType: 'json',
            success: function (data) {
                if(data.data.id != null){
                    var checkboxs = $('#checkboxBox input');
                    var checkboxValue = [];
                    for (var i = 0; i < checkboxs.length; i++) {
                        if(checkboxs[i].checked){
                            checkboxValue.push(checkboxs[i].value);
                        }
                    }

                    var param = {
                        trIds: checkboxValue,
                        deptId: data.data.id,
                    }
                    $.ajax({
                        url: '/JsDeptAuthority/addJsDeptAuthority',
                        data: param,
                        dataType: 'json',
                        type: 'post',
                        success: function (data) {

                        }
                    });
                    var layer = parent.layer;
                    layer.close(layer.index);
                }
            }
        });


    });
})